package router

import (
	"QImages/apis"
	"QImages/global"
	"net/http"

	"github.com/gin-gonic/gin"
)

// InitRouter 初始化路由
func InitRouter() *gin.Engine {
	r := gin.Default()

	r.GET("/ping", apis.Ping)

	v1 := r.Group("/api/v1")
	{
		// 用户接口
		v1.GET("/user/:token", apis.GetUserInfoByToken)
		v1.POST("/user/login", apis.Login)
		v1.POST("/user/register", apis.Register)
		// 功能接口
		v1.POST("/upload", apis.UploadImage)
		v1.GET("/refresh", apis.Refresh)
		v1.GET("/timeline", apis.GetTimeline)
		// 图片接口
		v1.GET("/images", apis.GetImages)
		v1.POST("/images", apis.PostImage)
		v1.GET("/image/:id", apis.GetImageById)
		v1.DELETE("/image/:id", apis.DelImageById)
		v1.PUT("/image/:id", apis.UpdateImage)
		// 评论接口
		v1.GET("/comments", apis.GetComments)
		v1.POST("/comments", apis.PostComment)
		v1.DELETE("/comment/:id", apis.DelCommentById)
		// 收藏
		v1.POST("/collect", apis.Collect)
		v1.DELETE("/collect", apis.CancelCollect)
		v1.GET("/collect", apis.GetCollections)
		// 静态资源
		v1.StaticFS("/photos", http.Dir(global.Config.PhotoPath))
	}
	return r
}
